#include <cstdio>
using namespace std;

int AWinGame(char, char, int(*win)[3]);
void FindMax(int[], int);

int main()
{
    int num;
    scanf(" %d", &num);
    int result[2][3] = {0}, win_statistics[2][3] = {0};

    char a, b;
    for (int i = 0; i < num; i++) {
        scanf(" %c %c", &a, &b);
        switch (AWinGame(a, b, win_statistics)) {
            case 0:
                result[0][1]++;
                result[1][1]++;
                break;
            case 1:
                result[0][0]++;
                result[1][2]++;
                break;
            case -1:
                result[0][2]++;
                result[1][0]++;
                break;
        }
    }

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++)
            printf("%d ", result[i][j]);
        printf("\n");
    }

    FindMax(win_statistics[0], 3);
    printf(" ");
    FindMax(win_statistics[1], 3);
    printf("\n");

    return 0;
}

int AWinGame(char a, char b, int (*win)[3])
{
    // win: B C J

    // B win
    if (a == 'C' && b == 'B') {
        win[1][0]++;
        return -1;
    }
    if (a == 'J' && b == 'C') {
        win[1][1]++;
        return -1;
    }
    if (a == 'B' && b == 'J') {
        win[1][2]++;
        return -1;
    }
    
    // A win
    if (b == 'C' && a == 'B') {
        win[0][0]++;
        return 1;
    }
    if (b == 'J' && a == 'C') {
        win[0][1]++;
        return 1;
    }
    if (b == 'B' && a == 'J') {
        win[0][2]++;
        return 1;
    }

    // dogfall
    return 0;
}

void FindMax(int x[], int len)
{
    int temp = 0;
    for (int i = 1; i < len; i++) 
        if (x[i] > x[temp])
            temp = i;
    switch (temp) {
        case 0:
            printf("B");
            break;
        case 1:
            printf("C");
            break;
        case 2:
            printf("J");
            break;
    }
}